package com.ol.edu.server.service.Authority.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ol.edu.server.entity.Menu;
import com.ol.edu.server.mapper.MenuMapper;
import com.ol.edu.server.service.Authority.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Roger
 * @date 2020/9/9 6:40
 * @description
 */
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;
    /*
        查询菜单列表
     */
    @Override
    public PageInfo<Menu> findAllMenu(Integer currentPage, Integer pageSize) {
        //获取分页数据
        PageHelper.startPage(currentPage, pageSize);
        List<Menu> menuList = menuMapper.findAllMenu();
        PageInfo<Menu> pageInfo = new PageInfo<>(menuList);
        return pageInfo;
    }
    /*
        根据菜单ID 查询菜单信息
     */
    @Override
    public Menu getMenuInfoById(Integer id) {
        return menuMapper.getMenuInfoById(id);
    }
    /*
        保存 菜单
     */
    @Override
    public void saveMenu(Menu menu) {
        if (menu.getParentId() != -1) {
            menu.setLevel(1);
        }
        menuMapper.saveMenu(menu);
    }
    /*
        修改菜单
     */
    @Override
    public void updateMenu(Menu menu) {
        menuMapper.updateMenu(menu);
    }

    @Override
    public void deleteMenu(Integer id) {
        menuMapper.deleteMenu(id);
    }
}
